/**
 * Gate is a superclass that has And, Or and Not as subclass.
 * Gate as only two fields, which are an ArrayList of InputPin objects
 * and an OutputPin object.
 * It implements to the interface Component, because it and its subclasses are component
 * and have to receive the component methods.
 * 
 * @author Simone D'Avico (simone.davico@usi.ch); Giuseppe Mendola (giuseppe.mendola@usi.ch);Gregory Banfi (gregory.banfi@usi.ch);
 * @version 24.05.2011
 */

package ch.usi.inf.pf2.Gates;

import java.util.ArrayList;

import ch.usi.inf.pf2.Component;
import ch.usi.inf.pf2.Value;
import ch.usi.inf.pf2.Wire;
import ch.usi.inf.pf2.pins.InputPin;
import ch.usi.inf.pf2.pins.OutputPin;

public abstract class Gate extends java.awt.Component implements Component {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public ArrayList<InputPin> inputPins;
	protected OutputPin outputPin;
	private ArrayList<Wire> InconnectedWires;
	private ArrayList<Wire> OutconnectedWires;

	/**
	 * Constructor of Gate. It generates a new ArrayList of InputPin objects,
	 * and assigns it to the inputPins field.
	 */
	public Gate(final ArrayList<InputPin> inputpins, final OutputPin outputPin){
		this.inputPins = new ArrayList<InputPin>();
		this.outputPin = new OutputPin(Value.UNKNOWN);
		InconnectedWires = new ArrayList<Wire>();
		OutconnectedWires = new ArrayList<Wire>();
	}
	
	public Value getValue() {
		return outputPin.getValue();
	}

	/**
	 * This method returns the ArrayList of the field inputPins
	 * 
	 * @return inputPins The inputPins field.
	 */
	@Override
	public ArrayList<InputPin> getInputPins() {
		return inputPins;
	}

	/**
	 * This method returns the OutputPin of the field outputPin
	 * 
	 * @return outputPin The outputPin field.
	 */
	@Override
	public OutputPin getOutputPin() {
		return outputPin;
	}

	@Override
	public void setInputPins(ArrayList<InputPin> inputPins) {
		this.inputPins = inputPins;
	}
	
	@Override
	public void addInConnectedWire(Wire wire) {
		InconnectedWires.add(wire);
	}
	
	@Override
	public ArrayList<Wire> getInConnectedWires() {
		return InconnectedWires;
	}
	
	@Override
	public void addOutConnectedWire(Wire wire) {
		OutconnectedWires.add(wire);
	}
	
	@Override
	public ArrayList<Wire> getOutConnectedWires() {
		return OutconnectedWires;
	}
}
